/*  
 * Library for InvisionFree-powered forum add-ons
 * Version 000001
 * Copyright sk89q <http://sk89q.therisenrealm.com>
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
*/

var SKIFS =
{
    util:
    {
        // gets the base URL to prepend to URLs
        getBaseUrl: function()
        {
            return location.href.match(/(http:\/\/.*?\/)index\.php/)[1];
        },
        getSessionId: function()
        {
            var sess = location.href.match(/s=([a-f0-9]{32})/);
            if(!sess) return '';
            return sess[1];
        },
        // get a XMLHttpRequest object
        getAjax: function()
        {
            if(window.XMLHttpRequest)
            {
                return new XMLHttpRequest();
            }
            else if(window.ActiveXObject)
            {
                try
                {
                    return new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(e)
                {
                    try
                    {
                        return new ActiveXObject("Microsoft.XMLHTTP");
                    }
                    catch(e)
                    {
                        return false;
                    }
                }
            }
            
            return false;
        },
        // make it safe to post
        utf8Decode: function(d)
        {
            var nd = '';
            for(var i = 0; i < d.length; i++)
            {
                var cc = d.charCodeAt(i);
                if(cc > 127)
                    nd += '&#'+cc+';';
                else 
                    nd += d.charAt(i)
            }
            
            return encodeURIComponent ? encodeURIComponent(nd) : escape(nd)
        }
    }
};
